﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AuroraWuBi
{
    public class WordFrequencyInfo
    {
        /// <summary>
        /// 是否为单字，1是，0否
        /// </summary>
        public bool IsSingleWord { get; set; }

        public string Word { get; set; }

        /// <summary>
        ///单字时： 原一级简码1级，原键面字2级，原二级简码3级， 一级常用2000字4级， 二级常用1500字5级；7000+8105+GB18030_2000+笔画、部首jvm第6级为6级，其他CJK为7级
        /// </summary>
        public int Frequency1 { get; set; }
        /// <summary>
        /// 字频
        /// </summary>
        public int Frequency2 { get; set; }

        


        public WordFrequencyInfo(bool isSingleWord,string word, int wordFrequency1, int wordFrequency2)
        {
            this.IsSingleWord = isSingleWord;
            this.Word = word;
            this.Frequency1 = wordFrequency1;
            this.Frequency2 = wordFrequency2;
        }
    }

    public class WordFrequencySort
    {

        /// <summary>
        /// 五笔编码为1 2 3码时排序，即单字排序
        /// </summary>
        /// <param name="WordFrequency1"></param>
        /// <param name="WordFrequency2"></param>
        /// <returns></returns>
        public static int SortByFrequency(WordFrequencyInfo WordFrequency1, WordFrequencyInfo WordFrequency2)
        {
            if (WordFrequency1.Frequency1.CompareTo(WordFrequency2.Frequency1) != 0)
                return (WordFrequency1.Frequency1.CompareTo(WordFrequency2.Frequency1));//按常用级别升序
            else if (WordFrequency1.Frequency2.CompareTo(WordFrequency2.Frequency2) != 0)
                return -(WordFrequency1.Frequency2.CompareTo(WordFrequency2.Frequency2));//按字频降序
            else if (WordFrequency1.Word.CompareTo(WordFrequency2.Word) != 0)
                return (WordFrequency1.Word.CompareTo(WordFrequency2.Word));//按字升序
            else
                return 1;
        }
        /// <summary>
        /// 五笔编码为4码时排序，即单字、词语混合排序
        /// </summary>
        /// <param name="WordFrequency1"></param>
        /// <param name="WordFrequency2"></param>
        /// <returns></returns>
        public static int SortByFrequency2(WordFrequencyInfo WordFrequency1, WordFrequencyInfo WordFrequency2)
        {
            if (WordFrequency1.Frequency1.CompareTo(WordFrequency2.Frequency1) != 0)
                return -(WordFrequency1.Frequency1.CompareTo(WordFrequency2.Frequency1));//按第1词频降序
            else if (WordFrequency1.Frequency2.CompareTo(WordFrequency2.Frequency2) != 0)
                return (WordFrequency1.IsSingleWord.CompareTo(WordFrequency2.IsSingleWord));//按是否单字
            else if (WordFrequency1.Frequency2.CompareTo(WordFrequency2.Frequency2) != 0)
                return -(WordFrequency1.Frequency2.CompareTo(WordFrequency2.Frequency2));//按第2词频降序
            else if (WordFrequency1.Word.CompareTo(WordFrequency2.Word) != 0)
                return (WordFrequency1.Word.CompareTo(WordFrequency2.Word));//按字升序
            else
                return 1;
        }
    }
}
